home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / tsbat146.zip / SWEEP.BAT < prev    next >
DOS Batch File  |  1994-01-13  |  3KB  |  94 lines

  1. @echo off
  2.  
  3. echo ┌──────────────────────────────────────────────────────┐
  4. echo │ SWEEP, Perform a command on a directory and below it │
  5. echo │ A batch demo by Prof. Timo Salmi Thu 13-Jan-94       │
  6. echo │ Draws on ideas of A.Reyes from PC-Mag Vol 12 No 19   │
  7. echo └──────────────────────────────────────────────────────┘
  8.  
  9. rem Is help needed
  10. if "%2"=="" goto _help
  11.  
  12. rem Put the names of the auxiliary files into environment variables.
  13. rem Edit the dir_ to point where you put this batch. But note that
  14. rem it is essential that the directory is at your path.
  15. set dir_=c:\dos
  16. set enter_=%dir_%\enter.com
  17. set bat_=%dir_%\sweep$$$.bat
  18. set dat_=%dir_%\sweep$$$.dat
  19. set new_=%dir_%\new.bat
  20.  
  21. rem The loadfix.com command can run any program including "Enter"
  22. if not exist c:\dos\loadfix.com goto _nofix
  23. copy c:\dos\loadfix.com %enter_% > nul
  24.  
  25. Rem Build an auxiliary file for performing the command on one subdirectory
  26. echo @echo off > %new_%
  27. echo if "%%3"=="" goto _out >> %new_%
  28. rem This is the crucial line. It has to command you wish to sweep with!
  29. rem Since this is just a demonstration I have put dir/w in there, but
  30. echo dir/w %%3\%2 >> %new_%
  31. echo :_out >> %new_%
  32.  
  33. rem Build a list of the directories on the directory and its subdirectories
  34. rem MsDos 5+ is required since dir does not have all the switches afore
  35. dir %1 /b /s /a:d > %dat_%
  36. echo %1 >> %dat_%
  37. echo. >> %dat_%
  38.  
  39. rem Build a file with "Enter" commands, to be run by loadfix
  40. echo @echo off > %bat_%
  41. date < %dat_% | find "Enter" | sort /r >> %bat_%
  42.  
  43. rem Run the set of "Enter" commands
  44. call %bat_%
  45.  
  46. rem Delete the auxiliary files
  47. if exist %enter_% del %enter_%
  48. if exist %bat_% del %bat_%
  49. if exist %dat_% del %dat_%
  50. if exist %new_% del %new_%
  51.  
  52. goto _out
  53.  
  54. :_nofix
  55. echo File c:\dos\loadfix.com needed, but not found
  56. goto _out
  57.  
  58. :_help
  59. echo @echo off> ms-dos.bat
  60. echo set ver_=%%2> ms-dos.bat
  61. ver> tmp$$$.bat
  62. echo Usage: SWEEP UpmostDirectory FileMask
  63. echo.
  64. echo Example: SWEEP C: *.BAK   (*NOT* SWEEP C:\ *.BAK, i.e. don't end with \)
  65. echo.
  66. echo Draws heavily on the ideas by Arneil P. Reyes in PC-Mag Vol 12 No 19.
  67. echo Also has several twists and improvements on my own like not requiring
  68. echo sweep.bat itself being at the path, showing the MsDos version,
  69. echo documentation within the batch, handling the upmost directory, etc.
  70. echo.
  71. echo Basically this batch answers the following FAQ (Frequently Asked
  72. echo Question). How can one sweep a directory and all its subdirectories
  73. echo with ordinary batch and MsDos commands only.
  74. echo.
  75. echo Requires at least MsDos 5.00
  76. call tmp$$$
  77. echo You seem to have MsDos version %ver_%
  78. if exist tmp$$$.bat del tmp$$$.bat
  79. if exist ms-dos.bat del ms-dos.bat
  80. echo.
  81. echo This is more of a demo than a production batch but it can be adjusted.
  82. echo The line to change is "echo dir/w %%%%3\%%2 >> %%new_%%"
  83. rem Note two tricks above, the quotes and the double percentage signs
  84. echo by replacing dir/w by any commands you wish to sweep with.
  85. goto _out
  86.  
  87. :_out
  88. set dir=_
  89. set bat_=
  90. set dat_=
  91. set enter_=
  92. set new_=
  93. set ver_=
  94.